//方法1
const fs =require("fs");
const path =require("path");
const stdin = process.stdin;

var tips = ['请输入要创建的文件夹','请输入要创建的文件','请输入要删除的文件'];
console.log(tips[0]);
var index=0;
var dirname="";

stdin.on('data',(chunk)=>{
    if(index==3){
        process.exit();
    }
    chunk=chunk.toString('utf-8');
    if(index==0){
        dirname=chunk.slice(6,-2); //输入的文件名
        
        var dirPath=path.join(__dirname, '/'+dirname);
        fs.mkdir(dirPath,(err)=>{
            if(err){
                console.log(err);
            }
            
        })
    }
    else if(index==1){
        filename=chunk.slice(6,-2);
        var filePath=path.join(__dirname, `/${dirname}/${filename}`);
        var writeable = fs.createWriteStream(filePath);
        writeable.write('hello node');
        writeable.end();
    }
    else {
        delfilename=chunk.slice(0,-2);
        // console.log(delfilename);
        var delfilePath=path.join(__dirname,`/${dirname}/${delfilename}`);
        // console.log(delfilePath);
        var fileObj=fs.statSync(delfilePath);
        // console.log(fileObj);
        fs.unlinkSync(delfilePath);
    }
    
    index++;
    console.log(tips[index]);
    
})